home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / tde40.zip / cfgcolor.c < prev    next >
C/C++ Source or Header  |  1994-06-05  |  14KB  |  515 lines

  1. /*
  2.  * Customize the colors in tde.
  3.  *
  4.  * Author:        Frank Davis
  5.  * Date:          July 21, 1991
  6.  * Compiler:      MSC 6.0a and QuickC 2.51
  7.  *
  8.  * This program is released into the public domain.  You may distribute
  9.  * it freely, Frank Davis
  10.  */
  11.  
  12.  
  13. #include <bios.h>
  14. #include <dos.h>
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <string.h>
  18.  
  19. #include "tdecfg.h"
  20. #include "cfgcolor.h"
  21.  
  22.  
  23. /*
  24.  * Default color settings.  Incidentally, I'm color blind (mild red-green) and
  25.  * the default colors look fine to me.
  26.  */
  27. COLORS colour = {
  28.    "$colors",
  29.    { { HERC_REVERSE, HERC_NORMAL, HERC_UNDER, HERC_REVERSE, HERC_REVERSE,
  30.      HERC_HIGH, HERC_NORMAL, HERC_NORMAL, HERC_HIGH, HERC_HIGH, HERC_HIGH,
  31.      HERC_REVERSE, HERC_REVERSE, HERC_NORMAL },
  32.    { COLOR_HEAD, COLOR_TEXT, COLOR_DIRTY, COLOR_MODE, COLOR_BLOCK,
  33.      COLOR_MESSAGE, COLOR_HELP, COLOR_WRAP, COLOR_EOF, COLOR_CURL, COLOR_RULER,
  34.      COLOR_POINTER, COLOR_TEXT, COLOR_OVRS } }
  35. };
  36.  
  37.  
  38. extern struct vcfg cfg;         /* video stuff */
  39. extern FILE *tde_exe;           /* FILE pointer to tde.exe */
  40. extern long color_offset;
  41.  
  42. COLORS temp_colours;            /* play around with colors in this array */
  43. static int index;               /* 0 = Monochrome colors, 1 = color colors */
  44.  
  45.  
  46. /*
  47.  * Name:    tdecolor
  48.  * Date:    July 21, 1991
  49.  * Notes:   Strategy is fairly straight forward -  1) initialize all the
  50.  *          variables  2) show the user a color sample  3) make the changes
  51.  *          permanent if desired.
  52.  */
  53. void tdecolor( void )
  54. {
  55.    initialize_color( );
  56.    show_init_sample( );
  57.    change_colors( );
  58.    restore_overscan( cfg.overscan );
  59. }
  60.  
  61.  
  62. /*
  63.  * Name:    initialize
  64.  * Date:    July 21, 1991
  65.  * Notes:   Set up all of the global variables.
  66.  */
  67. void initialize_color( void )
  68. {
  69.  
  70.    fseek( tde_exe, color_offset, SEEK_SET );
  71.    fread( (void *)&temp_colours, sizeof( COLORS ), 1, tde_exe );
  72.  
  73.    if (cfg.color == FALSE)
  74.       index = 0;
  75.    else
  76.       index = 1;
  77.  
  78.    fields[0].color = temp_colours.clr[index][HELP];
  79.    fields[1].color = temp_colours.clr[index][HEAD];
  80.    fields[2].color = temp_colours.clr[index][TEXT];
  81.    fields[3].color = temp_colours.clr[index][CURL];
  82.    fields[4].color = temp_colours.clr[index][DIRTY];
  83.    fields[5].color = temp_colours.clr[index][WARNING];
  84.    fields[6].color = temp_colours.clr[index][MODE];
  85.    fields[7].color = temp_colours.clr[index][WRAP];
  86.    fields[8].color = temp_colours.clr[index][CEOF];
  87.    fields[9].color = temp_colours.clr[index][OVERSCAN];
  88.    fields[10].color = temp_colours.clr[index][RULER];
  89.    fields[11].color = temp_colours.clr[index][RULER_PTR];
  90.    fields[12].color = temp_colours.clr[index][BLOCK];
  91.    fields[13].color = temp_colours.clr[index][HILITED_FILE];
  92.  
  93.    fields[0].show_me = show_help_color;
  94.    fields[1].show_me = show_fileheader_color;
  95.    fields[2].show_me = show_text_color;
  96.    fields[3].show_me = show_curl_color;
  97.    fields[4].show_me = show_dirty_color;
  98.    fields[5].show_me = show_warning_color;
  99.    fields[6].show_me = show_mode_color;
  100.    fields[7].show_me = show_wrapped_color;
  101.    fields[8].show_me = show_eof_color;
  102.    fields[9].show_me = show_overscan_color;
  103.    fields[10].show_me = show_ruler_color;
  104.    fields[11].show_me = show_rulerptr_color;
  105.    fields[12].show_me = show_block_color;
  106.    fields[13].show_me = show_hilitedfile_color;
  107. }
  108.  
  109.  
  110. /*
  111.  * Name:    restore_overscan
  112.  * Date:    April 1, 1993
  113.  */
  114. void restore_overscan( int overscan )
  115. {
  116.    ASSEMBLE {
  117.         mov     ah, 0x0b                /* function 0x0b */
  118.         mov     bl, BYTE PTR overscan   /* get new overscan color */
  119.         xor     bh, bh
  120.         push    bp
  121.         int     VIDEO_INT               /* video interrupt = 10h */
  122.         pop     bp
  123.    }
  124. }
  125.  
  126.  
  127. /*
  128.  * Name:    show_init_sample
  129.  * Date:    July 21, 1991
  130.  * Notes:   Draw all of the sample screens.
  131.  */
  132. void show_init_sample( void )
  133. {
  134. char *sample;
  135. int  line;
  136. int  i;
  137. int  j;
  138. int  k;
  139. int  l;
  140. char temp[6];
  141. char far *p;
  142.  
  143.    xygoto( -1, -1 );
  144.    sample = sample_screen[0];
  145.    for (line=0; sample != NULL; ) {
  146.       s_output( (char far *)sample, line, 0, 7 );
  147.       sample = sample_screen[++line];
  148.    }
  149.    for (i=0; i<NUM_COLORS; i++)
  150.       (*fields[i].show_me)();
  151.    sample = field_screen[0];
  152.    for (line=12, i=1; sample != NULL; line++,i++) {
  153.       s_output( (char far *)sample, line, 0, 7 );
  154.       sample = field_screen[i];
  155.    }
  156.    p = (char far *)temp;
  157.    for (i=0,k=0,line=17; i<8; i++, line++) {
  158.       for (j=0,l=0; j<16; j++, k++,l+=5) {
  159.          color_number( temp, k );
  160.          s_output( p, line, l, k );
  161.       }
  162.    }
  163.    for (i=0; i<NUM_COLORS; i++) {
  164.       color_number( temp, fields[i].color );
  165.       s_output( p, fields[i].line, fields[i].col, fields[i].color );
  166.    }
  167. }
  168.  
  169.  
  170. /*
  171.  * Name:    color_number
  172.  * Date:    July 21, 1991
  173.  * Passed:  dest:  buffer to store the color sample
  174.  *          num:   attribute number
  175.  * Notes:   Show the use what the foreground and background colors look like.
  176.  */
  177. void color_number( char *dest, int num )
  178. {
  179. int i, j, k;
  180. char temp[6];
  181.  
  182.    strcpy( dest, "[   ]" );
  183.    itoa( num, temp, 10 );
  184.    i = strlen( temp );
  185.    j = 4 - i;
  186.    for (k=0; i > 0; i--,j++, k++)
  187.       dest[j] = temp[k];
  188. }
  189.  
  190.  
  191. /*
  192.  * Name:    current_color_number
  193.  * Date:    July 21, 1991
  194.  * Passed:  dest:  buffer to store the color sample
  195.  *          num:   attribute number
  196.  * Notes:   Put '*' around the sample color to give the user an idea of where
  197.  *          the current field is.
  198.  */
  199. void current_color_number( char *dest, int num )
  200. {
  201. int i, j, k;
  202. char temp[6];
  203.  
  204.    strcpy( dest, "*   *" );
  205.    itoa( num, temp, 10 );
  206.    i = strlen( temp );
  207.    j = 4 - i;
  208.    for (k=0; i > 0; i--,j++, k++)
  209.       dest[j] = temp[k];
  210. }
  211.  
  212.  
  213. /*
  214.  * Name:    show_help_color
  215.  * Date:    July 21, 1991
  216.  */
  217. void show_help_color( void )
  218. {
  219. int color;
  220. int line;
  221.  
  222.    color = fields[0].color;
  223.    for (line=1; line <10; line++)
  224.       hlight_line( 1, line, 37, color );
  225.    hlight_line( 1,  10, 13, color );
  226.    hlight_line( 25, 10, 13, color );
  227. }
  228.  
  229.  
  230. /*
  231.  * Name:    show_fileheader_color
  232.  * Date:    July 21, 1991
  233.  */
  234. void show_fileheader_color( void )
  235. {
  236.    hlight_line( 41, 1, 38, fields[1].color );
  237. }
  238.  
  239.  
  240. /*
  241.  * Name:    show_text_color
  242.  * Date:    July 21, 1991
  243.  */
  244. void show_text_color( void )
  245. {
  246. int color;
  247.  
  248.    color = fields[2].color;
  249.    hlight_line( 41, 3, 38, color );
  250. /*   hlight_line( 41, 5, 38, color );  */
  251. }
  252.  
  253.  
  254. /*
  255.  * Name:    show_curl_color
  256.  * Date:    July 21, 1991
  257.  */
  258. void show_curl_color( void )
  259. {
  260.    hlight_line( 41, 4, 38, fields[3].color );
  261. }
  262.  
  263.  
  264. /*
  265.  * Name:    show_dirty_color
  266.  * Date:    July 21, 1991
  267.  */
  268. void show_dirty_color( void )
  269. {
  270.    hlight_line( 41, 5, 38, fields[4].color );
  271. }
  272.  
  273.  
  274. /*
  275.  * Name:    show_warning_color
  276.  * Date:    July 21, 1991
  277.  */
  278. void show_warning_color( void )
  279. {
  280.    hlight_line( 41, 9, 38, fields[5].color );
  281. }
  282.  
  283.  
  284. /*
  285.  * Name:    show_mode_color
  286.  * Date:    July 21, 1991
  287.  */
  288. void show_mode_color( void )
  289. {
  290.    hlight_line( 41, 10, 26, fields[6].color );
  291. }
  292.  
  293.  
  294. /*
  295.  * Name:    show_wrapped_color
  296.  * Date:    July 21, 1991
  297.  */
  298. void show_wrapped_color( void )
  299. {
  300.    hlight_line( 67, 10, 12, fields[7].color );
  301. }
  302.  
  303.  
  304. /*
  305.  * Name:    show_eof_color
  306.  * Date:    July 21, 1991
  307.  */
  308. void show_eof_color( void )
  309. {
  310.    hlight_line( 41, 8, 38, fields[8].color );
  311. }
  312.  
  313.  
  314. /*
  315.  * Name:    show_overcan_color
  316.  restore_overscan
  317.  * Date:    April 1, 1993
  318.  */
  319. void show_overscan_color( void )
  320. {
  321. int overscan;
  322.  
  323.    overscan = fields[9].color;
  324.    restore_overscan( overscan );
  325. }
  326.  
  327.  
  328. /*
  329.  * Name:    show_ruler_color
  330.  * Date:    July 21, 1991
  331.  */
  332. void show_ruler_color( void )
  333. {
  334.    hlight_line( 41, 2, 21, fields[10].color );
  335.    hlight_line( 63, 2, 16, fields[10].color );
  336. }
  337.  
  338.  
  339. /*
  340.  * Name:    show_rulerptr_color
  341.  * Date:    July 21, 1991
  342.  */
  343. void show_rulerptr_color( void )
  344. {
  345.    hlight_line( 62, 2, 1, fields[11].color );
  346. }
  347.  
  348.  
  349. /*
  350.  * Name:    show_block_color
  351.  * Date:    July 21, 1991
  352.  */
  353. void show_block_color( void )
  354. {
  355. int color;
  356. int line;
  357.  
  358.    color = fields[12].color;
  359.    for (line=6; line <